Skip to content

lib-manager: validate ELF sizes and offsets#10899

Open
lyakh wants to merge 1 commit into
thesofproject:mainfrom
lyakh:libmngr
Open

lib-manager: validate ELF sizes and offsets#10899
lyakh wants to merge 1 commit into
thesofproject:mainfrom
lyakh:libmngr

Conversation

@lyakh

@lyakh lyakh commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

The library manager loads ELF files from the host file-system. Those files have to be only root-writable, so they are relatively trust- worthy - if you're root, it's anyway "game over." Still it's good to verify for corrupt or maniputalte invalid ELF images.

The library manager loads ELF files from the host file-system. Those
files have to be only root-writable, so they are relatively trust-
worthy - if you're root, it's anyway "game over." Still it's good
to verify for corrupt or maniputalte invalid ELF images.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Copilot AI review requested due to automatic review settings June 12, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR hardens the library manager’s ELF module loading by validating segment sizes/offsets against the loaded library image to prevent out-of-bounds reads.

Changes:

  • Add overflow-safe size calculation for segment load sizes and validate segments stay within the preloaded library image.
  • Thread the firmware descriptor (desc) into allocation/loading paths to access total image size.
  • Add bounds-check logging for invalid segment metadata.

* ELF file segment offsets and sizes come from library files, so they
* have to be validated.
*/
const size_t lib_size = (size_t)desc->header.preload_page_count * PAGE_SZ;
Comment on lines +180 to +183
if (size_mul_overflow(mod->segment[idx].flags.r.length, PAGE_SZ, &size)) {
ret = -EOVERFLOW;
goto err;
}
src = UINT_TO_POINTER(file_offset + load_offset);
va_base = (void __sparse_cache *)UINT_TO_POINTER(mod->segment[idx].v_base_addr);
size = mod->segment[idx].flags.r.length * PAGE_SZ;
ret = lib_manager_load_data_from_storage(va_base, src, size, flags);
goto err;
}

src = UINT_TO_POINTER(file_offset + load_offset);
Comment on lines +188 to +190
"segment %d out of bounds: file_offset %#x, size %#zx, total %#zx",
idx, file_offset, size, lib_size);
ret = -ENOSPC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants